# 
# 
# Author: Seeger Chin
# e-mail: seeger.chin@gmail.com
# 
# Copyright (C) 2006 Ingenic Semiconductor Inc.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# 
# 

# OUT_OBJ_DIR is default the path which obj file output. 
# EXAMPLE: OUT_OBJ_DIR	:=	ucos_obj
# make will make a Folder usos_obj in jz4740 for obj file

OUT_OBJ_DIR	:=	r:/ucos_obj
OUT_APP		:=	aucosII


CROSS = #/home/yliu/mipseltools-nopic/bin/
# select which module to compile, set value to 1 for the module to compile, remain blank for the module not to compile
# -----------------------------
JZ4740_PAV = 1
#
#TOUCHTYPE :
#           0. No Touch driver
#           1. AK4182
#           2. JZ4740SADC
#
TOUCHTYPE  = 0

#LCDTYPE :
#           0. No LCD Driver
#           1. Samsung tft 480 * 272
#           2. FOXCONN 8-bit serial
#           3. slcd
#           4. AUO_A030FL01_V1
#LCDTYPE    = 1
LCDTYPE    = 3
#RTCTYPE :
#           0. No RTC Driver
#           1. jz4740RTC
RTCTYPE    = 0

#CODECTYPE :
#           0. No Codec Driver
#           1. jz4740 Codec
CODECTYPE = 0
WAVDECODE = 0
#KeyCTYPE :
#           0. No Key Driver
#           1. jz4740 Key
KEYTYPE = 0

#TouchPanelTYPE :
#           0. No Tpanel Driver
#           1. jz4740 Tpanel
TPANELTYPE = 0

MMC    = 0
#MMCTYPE :
#           1. SD card
#           2. Micro -SD card
MMCTYPE    = 1

CAMERA = 0
LWIP   = 0
UCGUI  = 0
UCFS   = 0
JPEG   = 0

UDC    = 0
MP3    = 0
NAND   = 0
UDCCPU = 0
GUIDEMO = 0
DM = 0
I2C = 0
FM = 0
USE_MIDWARE = 0
# ------------------------------

CC	:= $(CROSS)mipsel-linux-gcc
AR	:= $(CROSS)mipsel-linux-ar rcsv
LD	:= $(CROSS)mipsel-linux-ld
OBJCOPY	:= $(CROSS)mipsel-linux-objcopy
NM	:= $(CROSS)mipsel-linux-nm
OBJDUMP	:= $(CROSS)mipsel-linux-objdump




# Compiler flags to generate dependency files.
#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
GENDEPFLAGS := -MMD -MP -MF $(OUT_OBJ_DIR)/.dep



#CFLAGS	:= -mips32 -O2 -mno-abicalls -fno-pic -fno-builtin \
	   -fno-exceptions -ffunction-sections -finit-priority \
	   -fomit-frame-pointer -msoft-float -G 0


CFLAGS	:= -mips32 -Os -mno-abicalls -fno-pic -fno-builtin \
	   -fno-exceptions -ffunction-sections \
	   -fomit-frame-pointer -msoft-float -G 0 




LIBS	:= -lstdc++ -lc -lm -lgcc

TOP	:= ..
COREDIR	 := $(TOP)/jz4740/core
OSDIR	 := $(TOP)/src
ARCHDIR	 := $(TOP)/mips
SOCDIR	 := $(TOP)/jz4740
MMCDIR	 := $(TOP)/mmc
UCFSDIR  := $(TOP)/ucfs
LWIPDIR  := $(TOP)/lwip/src
UCGUIDIR := $(TOP)/ucgui
CORE     := $(TOP)/ucgui/Core
TOUCHDIR := $(TOP)/jz4740/drv/touch
UDCDIR   := $(TOP)/jz4740/udc_new
LCDDIR   := $(TOP)/jz4740/drv/lcd
RTCDIR   := $(TOP)/jz4740/drv/rtc
CODECDIR := $(TOP)/jz4740/drv/codec
WAVDIR   := $(TOP)/audio/wave
KEYDIR   := $(TOP)/jz4740/drv/key
TPANELDIR	:= $(TOP)/jz4740/drv/tpanel
I2CDIR	 := $(TOP)/jz4740/drv/i2c
MP3DIR   := $(TOP)/madplay/libmad-0.15.1b
ID3DIR   := $(TOP)/madplay/libid3tag-0.15.1b
MADDIR   := $(TOP)/madplay/madplay-0.15.2b
FMDIR	 := $(TOP)/jz4740/drv/fm

NANDDIR  := $(TOP)/jz4740/nand
UDCCPUDIR := $(TOP)/jz4740/udc_new
MIDWAREDIR := $(TOP)/midware

LIBDIR	:= $(TOP)/LIBS
ifeq ($(GUIDEMO),1)
LIBS += $(wildcard $(LIBDIR)/*.a)
endif
CFLAGS  += -DJZ4740_PAV=$(JZ4740_PAV)

CFLAGS += -DCAMERA=$(CAMERA) \
          -DUCGUI=$(UCGUI)   \
          -DUCFS=$(UCFS)     \
          -DMMC=$(MMC)       \
          -DJPEG=$(JPEG)     \
          -DTOUCH=$(TOUCHTYPE)\
	  -DMMCTYPE=$(MMCTYPE)

include  $(COREDIR)/core.mk

ifeq ($(UDCCPU),1)
include  $(UDCCPUDIR)/udc.mk
endif

ifeq ($(NAND),1)
include  $(NANDDIR)/nand.mk
endif


ifneq ($(KEYTYPE),0)
include $(KEYDIR)/key.mk
endif

ifneq ($(TPANELTYPE),0)
include $(TPANELDIR)/tpanel.mk
endif

ifeq ($(WAVDECODE),1)
include $(WAVDIR)/wave.mk
endif

ifneq ($(CODECTYPE),0)
include $(CODECDIR)/codec.mk
endif

ifneq ($(RTCTYPE),0)
include  $(RTCDIR)/rtc.mk
endif

ifneq ($(LCDTYPE),0)
include $(LCDDIR)/lcd.mk
endif

ifneq ($(TOUCHTYPE),0)
include $(TOUCHDIR)/touch.mk
endif

ifeq ($(MMC),1)
include $(MMCDIR)/mmc.mk
endif

ifeq ($(UCFS),1)
include $(UCFSDIR)/ucfs.mk
endif

ifeq ($(LWIP),1)
include $(LWIPDIR)/lwip.mk
endif

ifeq ($(UCGUI),1)
include $(UCGUIDIR)/ucgui.mk
endif

ifeq ($(USE_MIDWARE),1)
include $(MIDWAREDIR)/midware.mk
CFLAGS	+= -DUSE_MIDWARE=$(USE_MIDWARE)
endif

ifeq ($(CAMERA),1)
SOURCES	+= $(wildcard $(SOCDIR)/camera/*.c) $(SOCDIR)/drv/i2c.c 
CFLAGS += -I$(SOCDIR)/camera
VPATH  += $(SOCDIR)/camera
endif

ifeq ($(JPEG),1)
SOURCES	+= $(wildcard $(UCGUIDIR)/JPEG/*.c)
CFLAGS += -I$(UCGUIDIR)/JPEG
VPATH  += $(UCGUIDIR)/JPEG
endif

ifeq ($(UDC),1)
include $(UDCDIR)/udc.mk
endif

ifeq ($(MP3),1)
include $(wildcard $(MP3DIR)/mp3.mk)
endif

ifeq ($(I2C),1)
include $(I2CDIR)/i2c.mk
endif


ifeq ($(FM),1)
include $(FMDIR)/fm.mk
endif

#OBJS	:= $(addsuffix .o , $(basename $(notdir $(SOURCES))))
#HEADO	:= $(addsuffix .o , $(basename $(notdir $(HEADS))))
OBJS	:= $(addprefix $(OUT_OBJ_DIR)/,$(addsuffix .o , $(basename $(notdir $(SOURCES)))))
HEADO	:= $(addprefix $(OUT_OBJ_DIR)/,$(addsuffix .o , $(basename $(notdir $(HEADS)))))






APP	:= $(OUT_APP).elf


all:	$(APP)
	
	$(OBJCOPY) -O binary $(APP)  $(OUT_APP).bin
#	$(OBJDUMP) -d $(APP) > ucos.dump
#	$(NM) $(APP) | sort > ucos.sym
#	$(OBJDUMP) -h $(APP) > ucos.map

$(APP):	$(HEADO) $(OBJS) $(EXTLIBS) link.xn makefile
	$(CC) -nostdlib -T link.xn	-Wl,-gc-sections -Wl,--relax -o $@ $(HEADO) $(OBJS) $(EXTLIBS) $(LIBS)

$(OUT_OBJ_DIR)/%.o	:	%.c
	$(CC) $(CFLAGS) -o $@ -c $< $(GENDEPFLAGS)/$(notdir $(@)).d
.cpp.o:
	$(CC) $(CFLAGS) -fno-rtti -fvtable-gc -o $@ -c $<
$(OUT_OBJ_DIR)/%.o : %.S
#	$(CC) -c -mips32 -G 0 -I. -mno-abicalls -D_ASSEMBLER_ -D__ASSEMBLY__   $< -o $@
	$(CC) $(CFLAGS) -D_ASSEMBLER_ -D__ASSEMBLY__ -o $@ -c $< $(GENDEPFLAGS)/$(notdir $(@)).d

clean:
	rm -rf $(OUT_OBJ_DIR)
	rm -rf  $(OUT_APP).elf $(OUT_APP).bin
#	rm -fr *.o $(APP) $(OBJS) $(OTHER) *.sym *.map *.dump *.bin *.lib






# Create object files directory
$(shell mkdir $(OUT_OBJ_DIR) $(OUT_OBJ_DIR)/.dep/ 2>/dev/null)



# Include the dependency files.
-include  $(wildcard $(OUT_OBJ_DIR)/.dep/*)
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

	

